"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const request = require("request");
const utils = require("utils");
const subTool = require("./subTool.js");
const index = require("../../const/index.js");
async function requestNewCookie() {
  const url = "http://wlw.68.gd.cn/kyhl-weixin-1.0/card/login.do?responseFunction=findByiccidMarkCallback&iccidMark=898604D21922C2711703&rfm" + Math.random();
  let [err, data] = await request.postRequest(url, { rawValue: true })(
    {},
    {
      headers: {
        DNT: "1",
        Pragma: "no-cache"
      }
      // enableProxy: true,
      // rejectUnauthorized: false,
      // proxy: "http://127.0.0.1:8899",
    }
  );
  if (!utils.util.nilValue(err)) {
    return [err, void 0];
  }
  let { data: resultData, headers } = data || {};
  if (resultData && resultData["app_result_key"] === "0") {
    let resultCookie = subTool.getCookieFromHeader(headers);
    if (!utils.util.nilValue(resultCookie) && resultCookie) {
      return [void 0, resultCookie];
    }
    return [new utils.BaseErr(-5002, "获取新cookie接口header中set-cookie没有cookie...")];
  }
  let errorMsg = "获取新token失败";
  if (resultData && resultData["system_result_message_key"]) {
    errorMsg = resultData["system_result_message_key"];
  }
  return [new utils.BaseErr(-5001, errorMsg), void 0];
}
async function requestCardInfo(cookie) {
  const url = "http://wlw.68.gd.cn/kyhl-weixin-1.0/card/findCardInfo.do?iccidOrPhone=&responseFunction=findCardInfoCallback&rfm=" + Math.random();
  let [err, data] = await request.postRequest(url)(
    {},
    {
      headers: {
        "X-Requested-With": "XMLHttpRequest",
        Pragma: "no-cache",
        Cookie: `${index.JSESSIONIDKey}=${cookie || ""}`
      }
      // enableProxy: true,
      // rejectUnauthorized: false,
      // proxy: "http://127.0.0.1:8899",
    }
  );
  if (!utils.util.nilValue(err)) {
    return [err, void 0];
  }
  if (data && data["app_result_key"] === "0") {
    return [void 0, subTool.formatterData(data)];
  } else {
    let errorMsg = "获取流量卡数据失败...";
    if (data && data["system_result_message_key"]) {
      errorMsg = data["system_result_message_key"];
    }
    return [new utils.BaseErr(-5101, errorMsg), void 0];
  }
}
exports.requestCardInfo = requestCardInfo;
exports.requestNewCookie = requestNewCookie;
